<template>
	<div class="content">
		<div class="input size">
			<el-row class="demo-autocomplete">
				<!-- style="align-items: flex-end" -->
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline">
						<el-form-item label="物品名称" :label-width="formLabelWidth">
							<el-input v-model="getDataParamaPlatformGoods.query.name" autocomplete="off" placeholder="请输入内容"></el-input>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline" >
						<el-form-item label="物品类型" :label-width="formLabelWidth">
							<el-select v-model="getDataParamaPlatformGoods.query.type" placeholder="下拉选择">
								<el-option key="" label="全部" value=""></el-option>
								<el-option v-for="item in lxoption" :key="item.id" :label="item.name" :value="item.id">
								</el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline" >
						<el-form-item label="网站售价" :label-width="formLabelWidth">
							<el-input v-model="getDataParamaPlatformGoods.query.min_Price" style="width: 35%;" autocomplete="off" placeholder="min"></el-input>
							<el-input  style="width: 20%;" autocomplete="off" placeholder="——"></el-input>
							<el-input v-model="getDataParamaPlatformGoods.query.max_Price" style="width: 35%;" autocomplete="off" placeholder="max"></el-input>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline" >
						<el-form-item label="冷却时间" :label-width="formLabelWidth">
							<el-select v-model="getDataParamaPlatformGoods.query.cooling">
								<el-option v-for="item in Datas" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline" >
						<el-form-item label="物品状态" :label-width="formLabelWidth">
							<el-select v-model="getDataParamaPlatformGoods.query.state" placeholder="上架">
								<el-option label="全部" value=""></el-option>
								<el-option label="上架" value="1"></el-option>
								<el-option label="下架" value="0"></el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline">
						<el-form-item label="发货类型" :label-width="formLabelWidth">
							<el-select v-model="getDataParamaPlatformGoods.query.trade_type" placeholder="手动发货">
								<el-option key="" label="全部" value=""></el-option>
								<el-option v-for="item in optionleix" :key="item.value" :label="item.label" :value="item.value">
								</el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="2" class="inpt_in">
					<el-button style="width:5vw;" type="primary" @click="querySearchPlatformGoods">搜索</el-button>
				</el-col>
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline">
						<el-form-item label="商城价格系数" :label-width="formLabelWidth">
							<el-input v-model="saveParam.buy_percent" style="width: 35%;" autocomplete="off" placeholder="商城价格系数"></el-input>
							<el-input  style="width: 20%;" autocomplete="off" placeholder="   +" disabled=""></el-input>
							<el-input v-model="saveParam.increments" style="width: 35%;" autocomplete="off" placeholder="具体金额"></el-input>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="7" class="inpt_in">
					<el-form class="demo-form-inline" >
						<el-form-item label="发货平台" :label-width="formLabelWidth">
							<el-select v-model="saveParam.platform_id" placeholder="发货平台">
								<el-option v-for="item in fhptoption" :key="item.id" :label="item.name" :value="item.id">
								</el-option>
							</el-select>
						</el-form-item>
					</el-form>
				</el-col>
				<el-col :span="5" class="inpt_in">
					<el-button style="width: 5vw;" type="primary" @click="saveConfig">确定</el-button>
				</el-col>
			</el-row>
		</div>
		<div class="boder">
			<el-row>
				<el-table :data="tableDataPlatformGoods" border style="width: 100%" :header-cell-style="{'text-align':'center','color':'rgba(0,0,0,0.85)'}"
				 @selection-change="handleSelectionChange" stripe>
					<el-table-column fixed prop="id" label="物品id" width="160" align="center">
					</el-table-column>
					<el-table-column prop="name" label="物品名称" width="160" align="center">
					</el-table-column>
					<el-table-column prop="typeName" label="物品类型" width="160" align="center">
					</el-table-column>
					<el-table-column prop="marketHashName" label="market_hash_name" width="160" align="center">
					</el-table-column>
					<el-table-column prop="img" label="预览图" width="160" align="center">
						<template slot-scope="scope">
							<img v-if="scope.row.img" v-bind:src="scope.row.img" style="width:40px;height:40px;"></img>
							<!-- <el-button type="text" size="small" @click="clickRemovesDialogForm1 = true;insertOrUpdate=false;title='编辑商品';insertDataParama=scope.row;onLoadLX()">编辑</el-button>
							<el-button type="text" size="small" @click="xiajia(scope.row.id)">下架</el-button>                 -->
						</template>
					</el-table-column>
					<el-table-column prop="qualityName" label="品质" width="160" align="center">
					</el-table-column>
					<el-table-column prop="looking" label="外观" width="160" align="center">
					</el-table-column>
					<el-table-column prop="cooling" label="冷却时间" width="150" align="center">
					</el-table-column>
					<el-table-column prop="price" label="网站售价" width="150" align="center">
					</el-table-column>


					<el-table-column prop="zgjg" label="采购价格" width="150" align="center">
					</el-table-column>
					<el-table-column prop="tradeTypeName" label="发货类型" width="150" align="center"> 
					</el-table-column>
					<el-table-column prop="deliveryPlatformName" label="发货平台" width="150" align="center">
					</el-table-column>


					<el-table-column fixed="right" label="操作" width="150" align="center">
						<template slot-scope="scope">
							<el-button type="text" size="small" @click="shangxiajia(scope.row.id,1)">上架</el-button>
							<el-button type="text" size="small" @click="shangxiajia(scope.row.id,0)">下架</el-button>
						</template>
					</el-table-column>
				</el-table>
			</el-row>
			<el-pagination
				background
				layout="prev, pager, next,total"
				:page-count="getDataParamaPlatformGoods.pageCount"
				@current-change="handleCurrentChangePlatformGoods">
			</el-pagination>
			<!-- 新增 -->
			<!-- <el-dialog title="新增" :visible.sync="addDialogForm">
        <addModel @fatherMethod="clickAddDialogForm"></addModel>
      </el-dialog> -->
		</div>
	</div>
</template>

<script>
import api from '../../../api/Basicpath/index'
	export default {
		// components: {
		//   addModel
		// },

		data() {
			return {
				saveParam:{
					"platform_id":1,
					"buy_percent":"50%",
					"increments":20
				},
				getDataParamaPlatformGoods:{
					"currentPage":1,
					"pageSize":3,
					"total":100,
					"pageCount":0,
					"query":{
						"product_type":2,
						"trade_type":"",
						"name":"",
						"type":"",
						"state":"",
						"min_price":"",
						"max_price":"",
						"cooling":"",
						"delivery_platform":""
					}
				},
				input: '',
				// addModelShow: false,
				addDialogForm: false,
				form: {
					name: '',
					region: '',
					date1: '',
					date2: '',
					delivery: false,
					type: [],
					resource: '',
					desc: ''
				},
				formLabelWidth: '8vw',
				options: [],
				value: '',
				tableDataPlatformGoods: [],
				checked: false,
				checkeds: false,
				state1: '',
				state2: '',
				multipleSelection: [],
				lxoption: [], //类型
				Datas: [{
					label: '无冷却',
					value: "null"
				},
				{
					label: '1天',
					value: 1
				}, {
					label: '2天',
					value: 2
				}, {
					label: '3天',
					value: 3
				}, {
					label: '4天',
					value: 4
				}, {
					label: '5天',
					value: 5
				}, {
					label: '6天',
					value: 6
				}, {
					label: '7天',
					value: 7
				}], //冷却时间
				optionleix: [{
					label: '手动',
					value: 1
				}, {
					label: '自动',
					value: 2

				}], //发货类型
				fhptoption: [],
			}
		},
		methods: {
			clickAddDialogForm() {
				this.addDialogForm = !this.addDialogForm
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			toggleSelection(rows) {
				if (rows) {
					rows.forEach(row => {
						this.$refs.multipleTable.toggleRowSelection(row);
					});
				} else {
					this.$refs.multipleTable.clearSelection();
				}
			},
			handleCurrentChangePlatformGoods(pageNumber) {
				this.getDataParamaPlatformGoods.currentPage = pageNumber;
				this.loadGetDataParamaPlatformGoods();
			},
			querySearchPlatformGoods() {
				this.loadGetDataParamaPlatformGoods();
				this.getDataParamaPlatformGoods.pageCount=0
			},
			loadGetDataParamaPlatformGoods(){
				this.$axios.post(`${api}/gamemall/mallItem/searchListByPage`,this.getDataParamaPlatformGoods)
				.then( res => {
				// if(res.code === 200){
				// 	console.log(res.data.list);
				// 	this.tableDataPlatformGoods = res.data.list;
				// 	this.getDataParamaPlatformGoods.pageCount = res.data.pages;
				// 	for(var i =0;i<this.tableDataPlatformGoods.length;i++){
				// 		let x= this.tableDataPlatformGoods[i].priceLowC5;
				// 		let y= this.tableDataPlatformGoods[i].priceLowIgxe;
				// 		let z= this.tableDataPlatformGoods[i].priceLowRussia;
				// 		let min = ((x < y) ? x : y)<z?((x < y) ? x : y):z;
				// 		this.tableDataPlatformGoods[i].zgjg = min;
				// 		let tradeType= this.tableDataPlatformGoods[i].tradeType;
				// 		if(tradeType==1){
				// 			let z= this.tableDataPlatformGoods[i].tradeTypeName = '人工发货';
				// 		}else if(tradeType==2){
				// 			let z= this.tableDataPlatformGoods[i].tradeTypeName = '自动发货';
				// 		}else{
				// 			let z= this.tableDataPlatformGoods[i].tradeTypeName = '错误类型';
				// 		}
				// 	}
				// }else if(res.code === 500){
				// 	// this.$message({
				// 	// message: res.msg || '请求数据失败',
				// 	// type: 'warning'
				// 	// })
				// }

				console.log(res.data);
				if(res.data==null){
					this.getDataParamaPlatformGoods.currentPage = 1;
					this.getDataParamaPlatformGoods.pageCount = 0;
					this.tableDataPlatformGoods =[];
				}else{
					console.log(res.data.list);
					this.tableDataPlatformGoods = res.data.list;
					this.getDataParamaPlatformGoods.pageCount = res.data.pages;
					for(var i =0;i<this.tableDataPlatformGoods.length;i++){
						let x= this.tableDataPlatformGoods[i].priceLowC5;
						let y= this.tableDataPlatformGoods[i].priceLowIgxe;
						let z= this.tableDataPlatformGoods[i].priceLowRussia;
						let min = ((x < y) ? x : y)<z?((x < y) ? x : y):z;
						this.tableDataPlatformGoods[i].zgjg = min;
						let tradeType= this.tableDataPlatformGoods[i].tradeType;
						if(tradeType==1){
							let z= this.tableDataPlatformGoods[i].tradeTypeName = '人工发货';
						}else if(tradeType==2){
							let z= this.tableDataPlatformGoods[i].tradeTypeName = '自动发货';
						}else{
							let z= this.tableDataPlatformGoods[i].tradeTypeName = '错误类型';
						}
					}
				}

				})
				.catch( err =>{
				// this.$message({
				// 	message: err.msg || '请求数据失败',
				// 	type: 'warning'
				// 	})
				})
			},
			shangxiajia(id,status){
				let para = {
						"id":id,
						"state":status
					};
				this.$axios.post(`${api}/gamemall/mallItem/update`,para)
				.then( res => {
				if(res.code === 200){
					this.$message({
					message: '修改成功',
					type: 'warning'
					});
					this.querySearchPlatformGoods();
				}else if(res.code === 500){
					// this.$message({
					// message: res.msg || '请求数据失败',
					// type: 'warning'
					// })
				}
				})
				.catch( err =>{
				// this.$message({
				// 	message: err.msg || '请求数据失败',
				// 	type: 'warning'
				// 	})
				})
				
			},
			saveConfig(){
				this.$axios.post(`${api}/gamemall/config/saveMall`,this.saveParam)
				.then( res => {
				if(res.code === 200){
					this.$message({
					message: '修改成功',
					type: 'warning'
					})
				}else if(res.code === 500){
					// this.$message({
					// message: res.msg || '请求数据失败',
					// type: 'warning'
					// })
				}
				})
				.catch( err =>{
				// this.$message({
				// 	message: err.msg || '请求数据失败',
				// 	type: 'warning'
				// 	})
				})
			}
		},
		created:function (){
			this.loadGetDataParamaPlatformGoods();
			this.$axios.get(`${api}/gamemall/droplist/type`, {})
			.then(res => {
				this.lxoption = res.obj
			})
			.catch(err => {
				// this.$message({
				// 	message: '请求异常',
				// 	type: 'warning'
				// })
			});
			this.$axios.post(`${api}/gamemall/deliveryPlatform/getPlatformList`, {
				"state": 1
			})
			.then(res => {
				this.fhptoption = res.data
				console.log(res)
			})
			.catch(err => {
				// this.$message({
				// 	message: '请求异常',
				// 	type: 'warning'
				// })
			})
		}
	}
</script>

<style scoped>
	.content {
		width: 99%;
		height: 99%;
		margin-left: 0.5%;
		border: 1px solid #EBEEF5;
		background-color: #FFF;
		border-radius: 0.325rem;
	}

	.inpt_in {
		margin-top: 1%;
	}

	.boder {
		width: 98%;
		height: 75%;
		border: 1px solid #EBEEF5;
		margin-top: 2%;
		margin-left: 1%;
	}

	.size {
		font-size: 0.8rem;
		color: #606266;
	}
</style>
